package com.ljy.my_study.java.juc.phaser;

/**
 * @author lijunying
 * @date 2021/2/1 9:48
 */
public class PhaserTestMain {

    public static void main(String[] args) {
        MyPhaser myPhaser=new MyPhaser();
        int count=5;
        StudentTask[] studentTasks=new StudentTask[count];
        for(int i=0;i<count;i++){
            studentTasks[i]=new StudentTask(myPhaser);
            myPhaser.register();
        }

        Thread[] threads=new Thread[count];
        for(int i=0;i<count;i++){
            threads[i]=new Thread(studentTasks[i],"student "+i);
            threads[i].start();
        }
        for(int i=0;i<count;i++){
            try {
                threads[i].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("Phaser has finished:"+myPhaser.isTerminated());
    }

}
